<template>
  <div class="push-body">
    <!-- header部分 -->
    <nav-title :title="title" />
    <div style="width:100%;height:20px;">&nbsp;</div>
    <div v-for="(push,index) in processList" class="push-user" :for="'push' + index" v-bind:key="'push' + index">
      <input type="radio" :id="'push' + index" name="pushBox" v-model="chosedStepNbr" :value="push.cStepNbr"/>
      <i></i>
      <label :for="'push' + index" class="name">{{push.emplName}}</label>
      <label :for="'push' + index">({{push.descr}})</label>
    </div>
    <div style="height:100px;width:100px">
      &nbsp;
    </div>
    <div class="push-btn">
      <button @click="pushUser">驳回</button>
    </div>
  </div>
</template>

<script>
import {
  getProcessedNode,

  getCompensateApprove,
  getFormalApprove,
  getWastageApprove,
  approveMobilize,
  getRecruitmentApproveDrft,
  perresultApproveApel
} from '../../api/api'
import { json2Form } from '../../util/http'

export default {
  components: {},
  mounted() {
    this.params = this.$route.params
    console.error(this.params)
    this.cTransactionNbr = this.$route.params.c_TRANSACTION_NBR

    this.formalParams = this.$route.params.formalParams
    this.wastageParams = this.$route.params.wastageParams
    this.recruitmentParams = this.$route.params.recruitmentParams
    this.performanceAppeal = this.$route.params.performanceAppeal
    this.getProcessedNode();

    this.title = this.params.actionType == 'PushAllback' ? '退回（重走）' : '退回（不重走）';
  },
  data() {
    return {
      processList: [],
      title:'退回',
      chosedStepNbr:0,
      //按钮点击的参数
      cTransactionNbr: '',
      params:{},


      formalParams: {},
      wastageParams: {},
      recruitmentParams: {},
      performanceAppeal: {}
    }
  },
  methods: {
    //获取已完成节点
    getProcessedNode() {
      let params = {
        transNum: this.params.cTransactionNbr
      };
      getProcessedNode(params)
        .then(res => {
          if (res && res.retCode === "000000") {
            this.processList = res.retData;
            this.chosedStepNbr = res.retData[0].cStepNbr;
          } else {
            this.$vux.alert.show({
              title: "提示",
              content: res.retMsg
            });
          }
        })
        .catch(res => {
          this.$vux.alert.show({
            title: "警告",
            content: "网络异常，请稍后重试"
          });
        });
    },
    pushUser() {
      console.error(this.chosedStepNbr)
      if (!this.chosedStepNbr) {
        this.$vux.alert.show({
          title: '警告',
          content: '请选择驳回位置'
        })
        return
      }
      let approveFun = getCompensateApprove;
      switch(this.params.approveBizType){
        case "formal":
          approveFun = getFormalApprove
          break
        case "wastage":
          approveFun = getWastageApprove
          break
        case "mobilization":
          approveFun = approveMobilize
          break
        case "recruitment":
          approveFun = getRecruitmentApproveDrft
          break
        case "perresult":
          approveFun = perresultApproveApel
          break
        default:
          approveFun = getCompensateApprove
          break
      }
      this.params.cStepNbr = this.chosedStepNbr
      approveFun(json2Form(this.params))
        .then(res => {
          if (res && res.retCode === '000000') {
            let _this = this
            this.$vux.alert.show({
              title: '成功',
              content: '操作成功',
              onHide() {
                console.error("-------------------------------")
                console.error(_this.params.cLink)
                _this.$router.push({
                  name: _this.params.cLink ? _this.params.cLink : "todoList",
                  query: {
                    cTransactionNbr: _this.params.cTransactionNbr
                  }
                })
              }
            })
          } else {
            this.$vux.alert.show({
              title: '提示',
              content: res.retMsg
            })
          }
        })
        .catch(res => {
          this.$vux.alert.show({
            title: '警告',
            content: '网络异常，请稍后重试'
          })
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.push-body {
  height: 100%;
  /* background-color: #f2f2f2; */
  .search {
    text-align: left;
    .search-img {
      margin-left: 30px;
    }
    .search-input {
      width: 60%;
    }
  }
}

.container {
  background-color: #f2f2f2;
  margin-bottom: 20px;
  height: 40px;
  line-height: 40px;
}

.push-user {
  padding: 10px 10px 10px 10px;
  margin: 0px 10px 10px 10px;
  text-align: left;
  background-color: #f2f2f2;
  border-radius: 4px;
  >input[type="radio"]{
    display: none;
    &:checked{
      & + i{
        border: 5px solid #1CAAFE;
      }
    }
  }
  >i {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 1px solid #aaa;
    border-radius: 20px;
    margin-right: 10px;
    float: left;
  }
}
.push-user img {
  vertical-align: text-top;
}

.name {
  font-weight: bold;
}

.push-btn {
  width: 100%;
  margin: 0 auto;
  color: #fff;
  position: fixed;
  bottom: 15px;
  text-align: center;
}

.push-btn button {
  color: white;
  font-size: 16px;
  font-weight: 900;
  line-height: 40px;
  width: 250px;
  height: 40px;
  background-color: #1caafe;
  border-radius: 4px;
}
</style>
